package a_o2odata_deal.utils.zhibo_zf

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SQLContext

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2020/1/2 16:07
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object create_store {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.set("spark.debug.maxToStringFields", "500")
    //conf.setMaster("local[*]")
    conf.set("es.nodes", "192.168.1.157")
    conf.set("es.port", "9200")
    conf.set("cluster.name", "O2OElastic")
    conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.caseSensitive", "true")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    sc.setLogLevel("WARN")
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    //sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    /*import org.apache.spark.sql.functions._
    val tb_month1 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/1")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month2 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/2")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month3 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/3")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month4 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/4")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month5 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/5")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month6 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/6")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month7 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/7")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month8 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/8")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month9 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/9")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month10 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/taobao/10")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()
    val tb_month11 = sqlContext.read.orc("s3a://dws-data/g_data/2019/11/taobao/")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()

    val tm_month1 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/1")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month2 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/2")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month3 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/3")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month4 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/4")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month5 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/5")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month6 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/6")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month7 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/7")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month8 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/8")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month9 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/9")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month10 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/10")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()
    val tm_month11 = sqlContext.read.json(s"s3a://o2o-dataproces-group/panzonghao/zhibo/backups/tmall/11")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()


    val result = tb_month1
      .unionAll(tb_month2)
      .unionAll(tb_month3)
      .unionAll(tb_month4)
      .unionAll(tb_month5)
      .unionAll(tb_month6)
      .unionAll(tb_month7)
      .unionAll(tb_month8)
      .unionAll(tb_month9)
      .unionAll(tb_month10)
      .unionAll(tb_month11)
      .unionAll(tm_month1)
      .unionAll(tm_month2)
      .unionAll(tm_month3)
      .unionAll(tm_month4)
      .unionAll(tm_month5)
      .unionAll(tm_month6)
      .unionAll(tm_month7)
      .unionAll(tm_month8)
      .unionAll(tm_month9)
      .unionAll(tm_month10)
      .unionAll(tm_month11)

    result.repartition(4).write.json("s3a://o2o-dataproces-group/panzonghao/zhibo_zf/backups/all_userid")*/


    import org.apache.spark.sql.functions._
    val tb_month12 = sqlContext.read.orc("s3a://dws-data/g_data/2019/12/taobao/")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("taobao")).dropDuplicates()

    val tm_month12 = sqlContext.read.orc("s3a://dws-data/g_data/2019/12/tmall/")
      .selectExpr("userId","regional_ID","province","city","district","timeStamp").withColumn("platForm",lit("tmall")).dropDuplicates()

    tb_month12.unionAll(tm_month12).repartition(4)
      .write.json("s3a://o2o-dataproces-group/panzonghao/zhibo_zf/backups/all_userid/12")
  }

}















